import time
import random

def manu():
    print('=' * 21)
    print('= ' + '欢迎来到生词本小程序' + ' =')
    print('=     ' + '1:添加单词' + '     =')
    print('=     ' + '2:删除单词' + '     =')
    print('=     ' + '3:清空单词' + '     =')
    print('=     ' + '4:查看单词' + '     =')
    print('=     ' + '5:背诵单词' + '     =')
    print('=     ' + '6:退出系统' + '     =')
    print('=' * 21)

words = {}

def add():
    word = input('请输入您要添加的单词：')
    if word in words:
        print('该单词已存在，添加失败！！！')
        return
    meaning = input('请输入您要添加的单词意思：')
    words[word]=meaning
    print("添加成功！！！")

def delelte():
    word = input('请输入您要删除的单词：')
    if word not in words:
        print('该单词不存在，删除失败！！！')
        return
    del words[word]
    print("删除成功！！！")

def clear():
   words.clear()
   print('清空单词成功！！！')

def find():
    if len(words) != 0:
        print(words)
    else:
        print('生词本内容为空！！！')


def recite():
    wordlist = list(words.keys())
    rand = random.randint(0,len(wordlist)-1)
    meaning = input(f'请输入单词：{wordlist[rand]}的意思：')
    count = 2
    while count > 0:
        if meaning == words[wordlist[rand]]:
            print('太棒了')
            break
        else:
            meaning = input(f'再想想，你还有{count}次机会，请重新输入：{wordlist[rand]}的意思：')
            count -= 1
    else:
        print('看来你需要加强记忆哦！！！')


while True:
    manu()
    choice = input('请输入数字1-6进行操作：')
    if choice == '1':
        add()
    elif choice == '2':
        delelte()
    elif choice == '3':
        clear()
    elif choice == '4':
        find()
    elif choice == '5':
        recite()
        while True:
            num = input('是否继续背单词(1:继续 0:退出)？')
            if num == '1':
                recite()
            else:
                print('退出背单词模式！！！')
                break
    elif choice == '6':
        print('退出生词本小程序')
        time.sleep(3)
        break
    else:
        print('输入信息错误，请重新输入！！！')